import React from 'react';
import { Breadcrumb, Button, Form, Input, Message } from 'antd';
const FormItem = Form.Item;

let AccountInfo = React.createClass({

   contextTypes: {
    router: React.PropTypes.object
  },

  getInitialState() {
    return {
     loading: false,
     forms: {}
    }
  },

  componentDidMount() {
    this.fetch()
  },

  fetch() {
    let _me = this;
    Utils.sendAjax({
      url: 'user/info/find',
      callback: (result) => {
        if (result.code === '200') {
          this.setState({
            forms: result.data
          })
        } else {
          Message.error(result.message, 10);
        }
      }
    });
  },

  handleSubmit(e) {
    e.preventDefault();
    let me = this;
    let params = this.props.form.getFieldsValue();
    this.props.form.validateFields((errors, values) => {
      if (!!errors) {
        console.log('Errors in form!!!');
        return;
      }
      this.setState({
        loading:true
      });
      Utils.sendAjax({
        url: '/user/info/update',
        data: JSON.stringify(params),
        callback: (result) => {
          if (result.code === '200') {
            Message.success(result.message);
          } else {
           
            Message.error(result.message, 10);
          }
          me.setState({
              loading:false
          });
        }
      });
    });
  },

  handleRouter() {
    let goPathUrl= '/system/securityIndex';
    this.context.router.push({pathname: goPathUrl, state: {key: '2'}});
  },
  
  render() {
    const { getFieldProps } = this.props.form;
    const formItemLayout = {
      labelCol: {span: 4},
      wrapperCol: {span: 6},
    };
    return (
      <div className="inner-content">
        <Form horizontal form={this.props.form} >
          <FormItem
            {...formItemLayout}
            label="账户">
            <Input {...getFieldProps('userName', {initialValue: this.state.forms.userName})} disabled/>
          </FormItem>
          <FormItem
            {...formItemLayout}
            label="姓名">
            <Input {...getFieldProps('realName', {initialValue: this.state.forms.realName})} />
          </FormItem>
          <FormItem
            {...formItemLayout}
            label="联系电话">
            <p>{this.state.forms.mobilePhone}<a href="javascript:;" onClick={this.handleRouter} style={{marginLeft: 20}}>修改</a></p>
            <Input type="hidden" {...getFieldProps('mobilePhone', {initialValue: this.state.forms.mobilePhone})} />
          </FormItem>
          <FormItem
            {...formItemLayout}
            label="联系地址">
            <Input {...getFieldProps('address', {initialValue: this.state.forms.address})} />
          </FormItem>
           <FormItem
            {...formItemLayout}
            label="有效证件">
            <Input {...getFieldProps('cardNo', {initialValue: this.state.forms.cardNo})} />
          </FormItem>
          <FormItem
            {...formItemLayout}
            label="邮箱">
            <Input {...getFieldProps('email', {initialValue: this.state.forms.email})}/>
          </FormItem>
          <FormItem
            {...formItemLayout}
            label="紧急联系人">
            <Input {...getFieldProps('urgencyContacts', {initialValue: this.state.forms.urgencyContacts})}/>
          </FormItem>
           <FormItem
            {...formItemLayout}
            label="联系方式">
            <Input {...getFieldProps('urgencyPhone', {initialValue: this.state.forms.urgencyPhone})}/>
          </FormItem>
          <FormItem
            {...formItemLayout}
            label="收款方户名">
            <Input {...getFieldProps('payeeName', {initialValue: this.state.forms.payeeName})}/>
          </FormItem>
          <FormItem
            {...formItemLayout}
            label="收款方账号">
            <Input {...getFieldProps('payeeAccount', {initialValue: this.state.forms.payeeAccount})}/>
          </FormItem>
          <FormItem
            {...formItemLayout}
            label="开户行">
            <Input {...getFieldProps('bankName', {initialValue: this.state.forms.bankName})}/>
          </FormItem>
          <FormItem wrapperCol={{ span: 10, offset: 4 }} style={{ marginTop: 24 }}>
            <Button type="primary" loading={this.state.loading} onClick={this.handleSubmit}>保存</Button>
          </FormItem>
        </Form>
      </div>
    );
  }
});
AccountInfo = Form.create()(AccountInfo)
export default AccountInfo